//
//  ToolBarView.swift
//  Weibo项目
//
//  Created by vn on 16/7/24.
//  Copyright © 2016年 vn. All rights reserved.
//

import UIKit

class ToolBarView: UIView {

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
         setUpUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
    //添加控件
    func setUpUI(){
        
        addSubview(line1)
        addSubview(line2)
        
        
        
    let retweet_btn =  addChildButton("timeline_icon_retweet", title:"转发")
    let comment_btn =     addChildButton("timeline_icon_comment", title: "评论")
    let unlike_btn =    addChildButton("timeline_icon_unlike", title: "赞")
        
        
        
        
        //设置约束转发
        retweet_btn.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(comment_btn)
                
        }
        //评论
        comment_btn.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweet_btn.snp_trailing)
            make.width.equalTo(unlike_btn)
            
          }
        
        //赞
        unlike_btn.snp_makeConstraints { (make) -> Void in
            
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(comment_btn.snp_trailing)
            
            
        }
        
        line2.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweet_btn.snp_trailing)
            
            
        }
        
        line1.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            make.centerX.equalTo(comment_btn.snp_trailing)
            
            
        }

        
        
        
        
        
    }
    
    
    
    lazy var line1 = UIImageView(imageName:"timeline_card_bottom_line")
    lazy var line2 = UIImageView(imageName:"timeline_card_bottom_line")
    
    
    
    
    
    
    
    
    
    
    
    
    
    //创建button
    
    func addChildButton(imageName:String,title:String)->UIButton{
        
        
        let button = UIButton()
        
        button .setTitle(title, forState: UIControlState.Normal)
        button .setBackgroundImage(UIImage(named:"timeline_card_bottom"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), forState: UIControlState.Highlighted)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        
        button.setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        
        addSubview(button)
        
        return button
        
    }
    
    
    
    
    
    
    
}
